# -*- coding: utf-8 -*-
from PyQt5.QtCore import QThread, pyqtSignal
from spider import Spider


class NewTaskThread(QThread):
    success_signal = pyqtSignal(int, str, str)
    error_signal = pyqtSignal(int, str, str)

    def __init__(self, row_index, asin):
        super(NewTaskThread, self).__init__()
        self.spider = Spider()
        self.asin = asin
        self.row_index = row_index

    def run(self) -> None:
        response = self.spider.send(self.asin)
        if response:
            title, url = response
            self.success_signal.emit(self.row_index, title, url)
        else:
            title = "None"
            url = "None"
            price = "None"
            self.error_signal.emit(self.row_index, title, url)


class TaskThread(QThread):
    start_signal = pyqtSignal(int)

    def __init__(self, row_index, asin, widget):
        super(TaskThread, self).__init__(widget)
        self.row_index = row_index
        self.asin = asin

    def run(self):
        self.start_signal.emit(self.row_index)
        # print(self.row_index,self.asin)
